package com.bjpowernode.controller;

import com.bjpowernode.common.result.Result;
import com.bjpowernode.entity.query.TranSaveQuery;
import com.bjpowernode.service.TranService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
public class TranController {

    private final TranService tranService;


    @PostMapping("/api/tran")
    public Result createTran(@RequestBody TranSaveQuery tranSaveQuery) {
        if (tranService.createTran(tranSaveQuery) <= 0) {
            // 如果创建交易失败，返回错误结果
            return Result.FAIL("交易创建失败");
        }else {
            // 返回成功结果
            return Result.OK("交易创建成功");
        }
    }

    @GetMapping("/api/trans")
    public Result getTransByPage(Integer current) {
        return Result.OK(tranService.getTransByPage(current));
    }

    @GetMapping("/api/tran/{id}")
    public Result tranDetail(@PathVariable("id") Integer id){
        return Result.OK(tranService.tranDetail(id));
    }

}
